#ifndef ITEMROW_H
#define ITEMROW_H

#include <QObject>
#include <QList>
#include <QVector>

class QStandardItem;

class Item;
class Source;

class DummyRow;
class SourceRow;

class ItemRow : public QObject
{
    Q_OBJECT

public:
    ItemRow(Item *item);
    virtual ~ItemRow();

    Item *item();

    const bool validAndUnknownUrlInClipboard() const;

    SourceRow *sourceRow(Source *source);

    // ui

    QList<QStandardItem*> items() const;

    const bool hasItemInRow(QStandardItem *item) const;
    const bool hasItemInDummyRow(QStandardItem *item) const;

    SourceRow *sourceRow(QStandardItem *item);

    void itemChanged(QStandardItem *item);

    const int row() const;

    QStandardItem *firstColumnItem() const;

signals:
    void columnWidthChanged(int column);
    void multipleColumnWidthsChanged();
    void dummyStatusChanged();

    void select(Item *item);
    void select(Source *source);

protected:
    void createDummyItems();
    void createItems();
    void createDummyRow();

    void fillUp();

    void updateDummyRowStatus();

protected slots:
    void name_dataChanged();
    void quantity_dataChanged();
    void checked_changed();

    void item_nameChanged(QString name);
    void item_quantityChanged(uint quantity);
    void item_ignoreStateChanged(bool ignored);

    void clipboard_dataChanged();

    void item_sourceAdded(Source *source);
    void item_sourceRemoved(Source *source);

protected:
    Item *m_item;

    QStandardItem *m_nameItem;
    QStandardItem *m_quantityItem;
    QStandardItem *m_nullItem[2];

    DummyRow *m_dummyRow;

    QVector<SourceRow*> m_sourceRows;
};

#endif // ITEMROW_H
